#include "CacheThreadPool.h"
#include "Util/logger.h"
#include "Util/onceToken.h"
#include "Thread/ThreadPool.h"
namespace toolkit {

int CacheThreadPool::s_pool_size = 0;

INSTANCE_IMP(CacheThreadPool);

EventPoller::Ptr CacheThreadPool::getFirstPoller(){
    return dynamic_pointer_cast<EventPoller>(_threads.front());
}

EventPoller::Ptr CacheThreadPool::getPoller(){
    return dynamic_pointer_cast<EventPoller>(getExecutor());
}

CacheThreadPool::CacheThreadPool(){
    //创建当前cpu核心个数优先级最低的线程，目的是做些无关紧要的阻塞式任务，例如dns解析，文件io等
    auto size = s_pool_size > 0 ? s_pool_size : thread::hardware_concurrency();
    createThreads([](){
        EventPoller::Ptr ret(new EventPoller(ThreadPool::PRIORITY_LOWEST));
        ret->runLoop(false, false,"CacheThreadPool");
        return ret;
    },size);
}

void CacheThreadPool::setPoolSize(int size) {
    s_pool_size = size;
}
}
